package com.xiaofei.controller;
import com.xiaofei.Tools.Result;
import com.xiaofei.pojo.dept;
import com.xiaofei.service.insterface.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@Slf4j
public class DeptController {
    @Autowired
    private DeptService deptService;
    /*
    查询部门
    */
    @GetMapping("/depts")
    public Result getList() {
        log.info("查询部门");
        List<dept> deptList = deptService.getAll();
        log.info(deptList.toString());
        return Result.success(deptList);
    }
    /*
    删除部门
     */
    @DeleteMapping("/depts")
    public Result deleteById(Integer id){
        deptService.deleteById(id);
        return Result.success();
    }
    /*
    添加部门
     */
    @PostMapping("/depts")
    public Result addDept(@RequestBody dept dp){
        log.info("添加部门:{}",dp);
        deptService.addDept(dp);
        return Result.success();
    }
    /*
    根据id查询部门
     */
    @GetMapping("/depts/{id}")
    public Result getById(@PathVariable("id") Integer id){
        dept d = deptService.getById(id);
        log.info("根据查询部门成功:{}",d);
        return Result.success(d);
    }
    /*
    修改部门
     */
    @PutMapping("/depts")
    public Result updept(@RequestBody dept dp){
        log.info("修改部门:{}",dp);
        deptService.updept(dp);
        return Result.success();
    }
}










